Skip to content

Reduce background Git ref and port polling#4187

Open
Quicksaver wants to merge 25 commits into
pingdotgg:mainfrom
Quicksaver:fix/reduce-background-git-ref-port-polling
Open

Reduce background Git ref and port polling#4187
Quicksaver wants to merge 25 commits into
pingdotgg:mainfrom
Quicksaver:fix/reduce-background-git-ref-port-polling

Conversation

@Quicksaver

@Quicksaver Quicksaver commented Jul 20, 2026

Copy link
Copy Markdown

Summary

Reduce persistent background work from Git ref enumeration and preview port discovery while preserving freshness when users interact with either surface.

What Changed

  • Revalidate only the first Git-ref page every 20 seconds instead of polling every retained page every five seconds
  • Load cursor pages once per connected generation and expire inactive ref atoms after 30 seconds
  • Refresh local and remote refs immediately when the composer branch or Diff comparison menu opens
  • Replay the latest preview-discovery snapshot instead of running a duplicate subscription scan
  • Serialize snapshot replay with concurrent broadcasts so subscribers cannot regress to stale results
  • Roll back listener registration when initial snapshot replay fails so a defective subscriber cannot block later broadcasts
  • Serialize port scans before publication so an older slow scan cannot overwrite a newer snapshot
  • Scan immediately when managed terminal process sets change and ignore unchanged registrations or redundant removals
  • Run the broad port-discovery safety net every 20 seconds while idle and every 10 seconds when a listener is known

Why

During extended use, T3 Code's resident memory climbed past 6 GB even while idle, while the renderer sustained roughly 10% CPU and the machine became noticeably warm around the CPU and GPU clusters. That pattern indicated that background work was continuing without user interaction and could compound renderer and resource pressure over long sessions.

Diagnostics identified two repeatable sources of idle churn: every retained Git-ref query, including each loaded pagination page, owned its own five-second listRefs revalidation loop, while preview discovery launched a broad lsof scan every three seconds. Preview subscription initialization could also scan twice, and unchanged terminal process registrations caused redundant probes. The new schedules reduce that steady subprocess load while immediate menu refreshes, terminal-process-triggered scans, and adaptive safety-net polling preserve freshness at interaction time.

Validation

  • Port scanner focused suite passed with 8 tests, including concurrent replay ordering, failed-replay listener cleanup, and concurrent scan serialization
  • Targeted server and client-runtime type checks passed
  • Isolated authenticated web verification loaded local, worktree, and remote refs when the branch selector opened
  • git diff --check passed

Proof

No standalone proof artifacts were captured; the isolated browser verification is summarized above.


Note

Medium Risk
Touches preview discovery concurrency and VCS ref freshness schedules; incorrect ordering or replay could briefly show stale ports or refs, but changes are well-covered by focused PortScanner and vcs tests.

Overview
Cuts idle background work from Git ref polling and preview port discovery while keeping data fresh when users open branch or comparison menus.

VCS refs (vcs.ts): First-page revalidation moves from 5s → 20s; paginated cursor pages no longer tick on an interval. Inactive ref atoms expire after 30s (was 5 minutes). BranchToolbarBranchSelector and DiffPanel share refreshVcsRefsOnMenuOpen so local (and remote for Diff) refs refresh only when a menu opens, not on close.

Port discovery (PortScanner.ts, ws.ts): Broad lsof polling drops from 3s to 10s when listeners are known and 20s when idle. Scans and snapshot publish/replay are serialized (semaphores) so slow scans and concurrent subscribers cannot deliver stale results; failed initial replay unregisters the listener. Terminal PID registration triggers scans only when the process set actually changes. WebSocket subscribeDiscoveredLocalServers drops its duplicate initial scan()—subscribers get the latest snapshot via PortDiscovery.subscribe replay after retain.

Tests and BRANCH_DETAILS.md document the new intervals and concurrency behavior.

Reviewed by Cursor Bugbot for commit 1863288. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Reduce background Git ref and port polling intervals

  • Increases the port discovery fallback scan interval from 3s to 10s (active) or 20s (idle), and serializes concurrent scans and snapshot broadcasts in PortScanner.ts
  • New subscribers now receive an immediate snapshot replay on subscribe; the manual initial scan in ws.ts is removed in favor of this mechanism
  • Git ref revalidation interval increases from 5s to 20s, and the cached listRefs atom idle TTL drops from 5 minutes to 30 seconds in vcs.ts
  • Paginated cursor pages now emit a single one-shot refresh instead of polling repeatedly
  • Opening branch selector or diff panel base-ref menus triggers a VCS ref refresh via a new refreshVcsRefsOnMenuOpen helper; background polling no longer handles this on its own

Macroscope summarized 1863288.

- Poll first ref pages every 20 seconds and refresh menus on open
- Avoid duplicate port scans and adapt lsof polling to activity
- Document the retained freshness guarantees
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 05824f2b-558b-4257-bc2a-835cc74fffa4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Jul 20, 2026
Comment thread apps/server/src/preview/PortScanner.ts
@macroscopeapp

macroscopeapp Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

Changes polling intervals and adds concurrency serialization across multiple subsystems (VCS refs, port scanning, websocket handling). The behavioral scope affecting system responsiveness and new semaphore-based ordering warrants human review.

You can customize Macroscope's approvability policy. Learn more.

- Order subscription replay with concurrent snapshot broadcasts
- Cover replay ordering with a focused concurrent regression test
- Document the preview notification ordering guarantee
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Jul 23, 2026
Comment thread apps/server/src/preview/PortScanner.ts Outdated
- Remove listeners immediately when initial snapshot replay fails
- Cover continued broadcasts after a defective replay
@macroscopeapp
macroscopeapp Bot dismissed their stale review July 24, 2026 16:39

Dismissing prior approval to re-evaluate 33063a2

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 33063a2. Configure here.

Comment thread apps/server/src/preview/PortScanner.ts Outdated
- Prevent slow scans from overwriting newer snapshots
- Cover concurrent scan ordering with a deterministic regression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant